/**
 *
 */
package gemini.basic.dao.impl;

import gemini.basic.dao.DiscountScaleDao;
import gemini.basic.dao.GmnDao;
import gemini.basic.model.DiscountScale;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 *
 */
public class DiscountScaleDaoImpl extends HibernateDaoSupport implements
		DiscountScaleDao {

	private GmnDao gmnDao;

	public void setGmnDao(GmnDao gmnDao) {
		this.gmnDao = gmnDao;
	}

	@Override
	public DiscountScale getByValue(short discountScale) {
		DetachedCriteria dtCri = DetachedCriteria.forClass(DiscountScale.class);

		dtCri.add(Restrictions.eq("value", discountScale));

		List<Object> discaleList = gmnDao.findByCriteria(dtCri);

		DiscountScale result = null;
		if (discaleList != null && !discaleList.isEmpty()) {
			result = (DiscountScale) discaleList.get(0);
		}
		return result;
	}

}
